#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int t, a[3];

// r, g, b->k, 0, 0

int solve(int k) {
    int b[3];
    b[0] = a[0], b[1] = a[1], b[2] = a[2];

    swap(b[k], b[0]);

    if (b[2] < b[1]) swap(b[2], b[1]);

    if ((b[2]-b[1])%3) return INT_MAX;

    return b[2];
}
int main() {
    cin >> t;
    while(t--) {
        cin >> a[0] >> a[1] >> a[2];

        int res = INT_MAX;

        for (int i = 0; i < 3; i++)
            res = min(res, solve(i));
        
        if (res >= a[0]+a[1]+a[2]) cout << -1 << endl;
        else cout << res << endl;
    }
    return 0;
}